<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>宝典类型</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/qmsk-1.2.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="../js/dataTable.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script> 
<script type="text/javascript" src="../js/find.js"></script>
<script type="text/javascript" src="../js/commonSelecter.js"></script>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script type="text/javascript" >
var _pagination = null;
/**
 * 入口，和服务器的通信从此开始
 */
$(function() {
	refreshInput($(".serWrapper"));
	initShopSelecter();
	initSelect();
});


function initSelect(){
	var shopId = $('#shopID').val();
	if(IsEmpty(shopId)){
		$("#shopIsChoosed").removeAttr("checked");
	}
	$('#selectlesType').val("");
	$('#carcolName').val("");
}

/**
 * 初始化店面选择器
 */
function initShopSelecter() {
	refreshInput($(".serWrapper"));
	$("#shopID").attr("disabled", "disabled");

	$("#shopIsChoosed").bind("click", function() {
		var checked = $(this).attr("checked");
		if (checked) {
			$("#shopID").removeAttr("disabled");
		} else {
			$("#shopID").attr("disabled", "disabled");
			$("#shopID").empty();
		}
	});
}


/**
 * 为查找做准备，这里主要是生成查询条件对象
 */
function toSearch() {
	$("#carcollectionTable").empty();
	var name = $("#carcolName").val();
	var lesId = $("#selectlesType").val();
	if(IsEmpty(lesId)){
		lesId= '';
	}
	_pagination = new Pagination({
		url : '../carCollection/find/opt',
		data : {
			name : name,
			lesId : lesId
		},
		success : printDataToPage,
		pageSize : 10
	});
}

/**
 * 删除一行
 */
function toDelete(id,lesId,row) {
	if (IsEmpty(id)) {
		artError('未获取到主要信息！');
		return false;
	}
	
	
	artConfirm("确认删除吗？", function() {
		qmsk.post("../carCollection/del",{'id' : id}, function(rst) {
			artSuccess("删除成功！");
			toSearch();
		});
	});
}


function printDataToPage(message){
	var oldBillNo = null;
	dataTable({
		tbodyId : 'carcollectionTable',
		heads : [ "name", "lesName", ["id","lesId"]],
		rst : message,
		handler : [{
			col : 2,
			f : detail
		}],
		sup : {
			id : "sup",
			template : "共 [index] 条"
		}
	});
}

/**
 * 隐藏添加弹出层
 */
function hideAddPanel() {
	$("#window_change,#yinying1").hide();
}

/**
 * 隐藏添加弹出层
 */
function hideAddPanel1() {
	$("#window_change1,#yinying1").hide();
}

function selectlesTypeser(){
	var shopId = $('#shopID').val();
	if(IsEmpty(shopId)){
		artError("请先选择店面");
		return false;
	}
	$("#selectlesType").blur();
	initSelecter({
		url : '../carLesson/find/opt',
		data: {"shopId":shopId},
		heads : ["shopName", "name"],
		titles : ["店名称", "大类名称"],
		zindex : 500,
		callBack : callBack
	});
}

function callBack(response, row) {
	var id = response.getValue('id', row);
	var name = response.getValue('name', row);
	$("#selectlesType").append("<option value='" + id + "' selected=\"selected\" >" + name + "</option>");
}

function selectlesType(){
	var shopId = $('#shopID').val();
	$("#editLesType").blur();
	$("#addLesType").blur();
	if(IsEmpty(shopId)){
		artError("请先选择店面");
		return false;
	}
	addMargin($("#window3"));
	new Pagination({
		url : '../carLesson/find/opt',
		data: {"shopId":shopId},
		success : lrgTypeF,
		pagerHandler:'carcollecPager',
		pageSize : 10
	});
	$("#window3,#yinying").show();
}

function lrgTypeF(message){
	dataTable({
		tbodyId : 'tLestype',
		heads : ["shopName", "name", ["id"]],
		handler : [{
			col : 2,
			f : lrgTypebtn
		}],
		trGender:trGender,
		rst : message
	});
	addMargin($("#window3"));
}

/*
*重置tr标签
*/
function trGender(row){
	if(IsNotEmpty(row)){
		return "<tr id='Id"+row+"'></tr>";
	}
}

function lrgTypebtn(heads, row){
	return "<input class='common_btn' type='button' value='选择' onclick='toSelected("+heads+","+row+")'>";
}

function toSelected(id,row){
	var tpname =$("#Id"+row).find("td:eq(1)").text();
	$("#editLesType").append("<option value='" + id + "' selected=\"selected\" >" + tpname + "</option>");
	$("#addLesType").append("<option value='" + id + "' selected=\"selected\" >" + tpname + "</option>");;
	$("#window3,#yinying").hide();
}

function toAdd(){
	$("#addName").val("");
	$("#addLesType").empty();
	$("#window_change,#yinying1").show();
	addMargin($("#window_change"));
}

function toEdit(id,lesId){
	$("#window_change1,#yinying1").show();	
	addMargin($("#window_change1"));
	var rst = _findInfo("../carCollection/find/id",{"id":id});
	if (IsNotEmpty(rst)){
  		$("#editLesType").append("<option value='" + getHtmlString(getHeadIndexValue(0,rst,'lesId')) + "' selected=\"selected\" >" + getHtmlString(getHeadIndexValue(0,rst,'lesName')) + "</option>");
		$("#editName").val(getHtmlString(getHeadIndexValue(0,rst,'name')));
		$("#carcolId").val(getHtmlString(getHeadIndexValue(0,rst,'id')));
	}
}

function edit(){
	var lesId = $("#editLesType").val();
	var name = $("#editName").val();
	var id = $("#carcolId").val();
	if(IsEmpty(lesId)){
		art.dialog({fixed:true, lock: true,content:"车务类型不能为空",icon:'error',ok:true});	
		return false;
	}
	
	if(IsEmpty(name)){
		art.dialog({fixed:true, lock: true,content:"名称不能为空",icon:'error',ok:true});	
		return false;
	}
	
	if(IsEmpty(id)){
		art.dialog({fixed:true, lock: true,content:"id不能为空",icon:'error',ok:true});	
		return false;
	}
	var heads = new Array("name","lesId" ,"id");
	var datas = new Array(name,lesId,id);
	
	var parser = new Object();
	var jsonParserStr = null;
	if (IsNotEmpty(datas)){
		addToParser(heads, datas, "edit" , parser);
		jsonParserStr =  JSON.stringify(parser);
	}
	
	qmsk.post("../carCollection/edit", {
		data : jsonParserStr
	}, function() {
		artSuccess("修改成功！");
		hideAddPanel1();
		if (_pagination) {
			_pagination.reload();
		}
	});
}

function add() {
	var lesId = $("#addLesType").val();
	var name = $("#addName").val();
	if(IsEmpty(name)){
		art.dialog({fixed:true, lock: true,content:"类型不能为空",icon:'error',ok:true});	
		return false;
	}
	
	if(IsEmpty(lesId)){
		art.dialog({fixed:true, lock: true,content:"车务类型不能为空",icon:'error',ok:true});	
		return false;
	}
	var heads = new Array("name", "lesId");
	var datas = new Array(name,lesId);
	
	var parser = new Object();
	var jsonParserStr = null;
	if (IsNotEmpty(datas)){
		addToParser(heads, datas, "add" , parser);
		jsonParserStr =  JSON.stringify(parser);
	}
	
	qmsk.post("../carCollection/insert", {
		data : jsonParserStr
	}, function() {
		artSuccess("添加成功！");
		hideAddPanel();
		toSearch();
	});
}

function detail(heads, row){
	return	"<input class='del common_btn' type='button' value='删除' onclick='toDelete("+heads[0]+","+heads[1]+","+row+")'>"+"<input class='edit common_btn' type='button' value='修改' onclick='toEdit("+heads[0]+","+heads[1]+")'>";
}


</script>
</head>

<body>
		<div id="yinying"></div>
		<div id="yinying1"></div>
			<div class="hideDiv hideOver" id="window3" style="width: 600px;">
			 <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
				<table id="tabLrgtype" width="100%" cellspacing="1" cellpadding="0" border="0" class="member_list">
			    	<caption>车务类型列表</caption>
			    	<thead>
				    	<tr>
				        	<th>所属店面</th>
				        	<th>车务类型名称</th>
				        	<th>操作</th>
				        </tr>
			        </thead>
			        <tbody id="tLestype">
			        </tbody>
			    </table>
 				<div id="carcollecPager" class="pager"></div>
 			</div>
 			
		
		<!-- 添加记录 弹出层 -->
		<div id="window_change" class="member_search hideDiv">
			<div class="closeTop">
				<span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span>
			</div>
			<p>
				<label style="margin-left:140px"><span>宝典类型名称：</span>
					<input type="text" id="addName" class="absoluteTxt">
				</label>
				<label style="margin-left:140px"><span>车务类型名称：</span>
					<select id="addLesType" onclick="selectlesType()"></select>
				</label>
			</p>

			<div class="submit_btn">
				<input type="button" value="保存信息" class="common_btn" id="saveButton" onclick="add()">
			</div>
		</div>
		
		<div id="window_change1" class="member_search hideDiv">
			<div class="closeTop">
				<span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span>
			</div>
			<p>
				<label style="margin-left:140px"><span>宝典类型名称：</span>
					<input type="text" id="editName" class="absoluteTxt">
					<input type="hidden" id="carcolId">
				</label>
				<label style="margin-left:140px"><span>车务类型名称：</span>
					<select id="editLesType" onclick="selectlesType()"></select>
				</label>
			</p>

			<div class="submit_btn">
				<input type="button" value="保存信息" class="common_btn" id="editButton" onclick="edit()">
			</div>
		</div>

<div class="container" id="container">
  <div class="container_R fr" style="padding:17px;width:773px;">
    <div class="place">宝典类型</div>
    <div class="member_search">
      <p>
      	<span> <input type="checkbox" id="shopIsChoosed"
			style="width: auto; height: auto; border: none;"> 店面：
		</span><select id="shopID"  class="shopName" onclick="openShopListPanel(this)" style="height: 20px;width: 150px;"></select>
      <span>
         宝典类型名称：<input type="text" id="carcolName" class="absoluteTxt"></span>
        <span>车务类型名称：<select id="selectlesType" onclick="selectlesTypeser()"></select></span>
        <span><input type="button" value="查询" class="btn" onclick="toSearch()"></span>
      </p>
    </div>
    <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
      <caption>
      <strong>宝典类型列表 <span id="sup">共0条</span></strong><input
						type="button" class="common_btn" value="新增" id="addColumn" onclick="toAdd()">
      </caption>
      <thead>
        <tr>
          <th>宝典类型名称</th>
          <th>车务类型名称</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody id="carcollectionTable">
      
      </tbody>
    </table>
     <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="pager" class="pager"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
</script>
</body>
<!-- InstanceEnd -->
</html>
